package com.cn.auth.security.config;


import com.cn.auth.security.entity.ZxcmsUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;


/**
 * describe:
 * current user Maochao.zhu
 * current system 2020/6/4
 */
@Configuration
public class UserDetailService implements UserDetailsService {
    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // 模拟一个用户，替代数据库获取逻辑
        ZxcmsUser user = new ZxcmsUser();
        user.setUname(username);
        user.setPwd(passwordEncoder.encode("123456"));
        System.out.println("--加密密码------"+user.getPwd());
        return new User(username, user.getPwd(), AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }
}
